//
//  LHBaseController.swift
//  sina_weibo
//
//  Created by 刘刘海强 on 16/5/11.
//  Copyright © 2016年 chuanzhi. All rights reserved.
//

import UIKit

class LHBaseController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.backgroundColor = UIColor.whiteColor()
        
//        tabBarItem = LHCustomTabBar()
        let lhTabBar = LHCustomTabBar()
        
        lhTabBar.callBackClosure = {[weak self] in
            print("点击了添加按钮")
            self!.showComposeVC()
            
        }
        
        setValue(lhTabBar, forKey: "tabBar")
        
        addChildViewController(LHHomeController(), title: "首页", imageName: "tabbar_home")
        addChildViewController(LHMessageController(), title: "消息", imageName: "tabbar_message_center")
        addChildViewController(LHDiscoverController(), title: "发现", imageName: "tabbar_discover")
        addChildViewController(LHProfileController(), title: "我的", imageName: "tabbar_profile")
        
        
        
    }
    
    func addChildViewController(childController: UIViewController, title: String, imageName: String) {
        
        childController.title = title
        //单独修改tableBar文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName:UIFont.systemFontOfSize(14)] , forState: .Normal)
        
        childController.tabBarItem.image = UIImage(named: imageName)
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")
        //修改图片的渲染模式
        childController.tabBarItem.selectedImage = UIImage(named: imageName + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        let nav = UINavigationController(rootViewController: childController)
        
        addChildViewController(nav)
        
    }
    
    
    //跳转compose控制器
    private func showComposeVC() {
        let composeController = LHComposeController()
        let Nav = UINavigationController(rootViewController: composeController)
        presentViewController(Nav, animated: true, completion: nil)
    }

 
    



}
